package com.zhuangfei.hpuhelper.tools;

import com.hpu.bean.Info;
import com.hpu.constants.HttpConstants;
import com.hpu.constants.ShareConstants;
import com.hpu.parser.InfoParser;
import com.hpu.tools.ShareTools;
import com.zhuangfei.hpuhelper.view.EmptyRoomActivity;
import com.zhuangfei.hpuhelper.view.LoadActivity;
import com.zhuangfei.hpuhelper.view.MainActivity;
import com.zhuangfei.hpuhelper.view.OptionalClassActivity;
import com.zhuangfei.toolkit.tools.ToastTools;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.View.OnAttachStateChangeListener;
import android.widget.Toast;

public class DefaultHandler extends Handler {

    Context context;

    public DefaultHandler(Context context) {
        this.context = context;
    }

    private int preWhat=-100;
    private int preCount=0;

    /**
     * 这段解决的方式有问题
     * @return
     */
    public boolean isIgnoreVpnExpired() {
        return preCount>2;
    }

    @Override
    public void handleMessage(Message msg) {
        if (context == null) return;

        if(msg.what==HttpConstants.VPN_TOOLONG){
            if(preWhat==HttpConstants.VPN_TOOLONG){
                preCount++;
            }else{
                preCount=1;
            }
        }else{
            preCount=0;
        }
        preWhat=msg.what;

        switch (msg.what) {

            case HttpConstants.QUERY_BOOK_BORROW__ERROR:
                ToastTools.show(context, "查询借阅情况失败!");
                break;

            case HttpConstants.QUERY_ELECTRIC__ERROR:
                ToastTools.show(context, "查询电费失败!");
                break;
            case HttpConstants.QUERY_BODY_SCORE__ERROR:
                ToastTools.show(context, "查询体测成绩失败!");
                break;

            // 登录异常
            case HttpConstants.LOGIN_ERROR:
                Toast.makeText(context, "登录异常！", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.NOEXPECT:
                Toast.makeText(context, "不期望的返回值！", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.GET_IMAGEPATH_ERROR:
                Toast.makeText(context, "获取图片路径出错！", Toast.LENGTH_SHORT).show();
                break;


            case HttpConstants.DOWNLOAD_IMAGE_ERROR:
                Toast.makeText(context, "获取个人头像失败！", Toast.LENGTH_SHORT).show();
                break;

            // 请求参数不全
            case HttpConstants.NEED_INFO:
                Toast.makeText(context, "参数不全", Toast.LENGTH_SHORT).show();
                break;

            // 教务处密码错误
            case HttpConstants.LOGIN_JWPASSWORD_ERROR:
                Toast.makeText(context, "教务处密码错误", Toast.LENGTH_SHORT).show();
                break;

            // 密匙错误
            case HttpConstants.KEY_ERROR:
                Toast.makeText(context, "密匙错误", Toast.LENGTH_SHORT).show();
                break;

            // vpn密码错误
            case HttpConstants.LOGIN_PASSWORD_ERROR:
                Toast.makeText(context, "学号或VPN密码错误", Toast.LENGTH_SHORT).show();
                break;

            // 获取个人数据失败
            case HttpConstants.QUERY_INFO_ERROR:
                Toast.makeText(context, "获取个人信息异常!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.QUERY_ROOM_ERROR:
                Toast.makeText(context, "查询空教室异常!", Toast.LENGTH_SHORT).show();
                break;

            // 获取课程失败
            case HttpConstants.QUERY_COURSE_ERROR:
                Toast.makeText(context, "获取课程信息异常!", Toast.LENGTH_SHORT).show();
                break;

            // 校准时间失败
            case HttpConstants.QUERY_WEEK_ERROR:
                Toast.makeText(context, "校准周次失败!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.QUERY_SCORE_ERROR:
                Toast.makeText(context, "查询成绩异常!", Toast.LENGTH_SHORT).show();
                break;

            // 获取成绩异常
            case HttpConstants.QUERY_FAILSCORE_ERROR:
                Toast.makeText(context, "查询不及格成绩异常!", Toast.LENGTH_SHORT).show();
                break;

            // 获取成绩异常
            case HttpConstants.QUERY_ALLSCORE_ERROR:
                Toast.makeText(context, "查询历年成绩异常!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.QUERY_CLASS_ERROR:
                Toast.makeText(context, "获取任选课异常!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.QUERY_SCHOOLNEWS_ERROR:
                Toast.makeText(context, "获取校内新闻失败!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.QUERY_XUEYUAN_NEWS_ERROR:
                Toast.makeText(context, "获取学院新闻失败!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.QUERY_SCHOOL_NOTICE_ERROR:
                Toast.makeText(context, "获取学校公告失败!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.QUERY_XUEYUAN_NOTICE_ERROR:
                Toast.makeText(context, "获取学院公告失败!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.QUERY_BOOK_ERROR:
                Toast.makeText(context, "查询图书失败!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.QUERY_LECTURE_ERROR:
                Toast.makeText(context, "查询讲座失败!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.DOWNLOAD_ERROR:
                Toast.makeText(context, "下载失败!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.SHARE_COURSE_DOWNLOAD_ERROR:
                Toast.makeText(context, "下载课程异常!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.SHARE_COURSE_DOWNLOAD_FAIL:
                Toast.makeText(context, "下载课程失败!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.SHARE_COURSE_UPLOAD_ERROR:
                Toast.makeText(context, "上传课程异常!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.SHARE_COURSE_UPLOAD_FAIL:
                Toast.makeText(context, "上传课程异常!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.SHARE_COURSE_UPLOAD_OVERLENGTH:
                Toast.makeText(context, "字符过长，上传失败!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.LOGIN_PEOPLE_OVER:
                Toast.makeText(context, "在线人数超过最大限制,稍后重试!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.QUERY_VERSION_ERROR:
                Toast.makeText(context, "检查版本失败!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.NO_INTERNET:
                Toast.makeText(context, "网络未连接!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.LOG_UPLOAD_ERROR:
                Toast.makeText(context, "日志上传异常!", Toast.LENGTH_SHORT).show();
                break;

            case HttpConstants.UPLOAD_HEAD_IMAGE_ERROR:
                Toast.makeText(context, "头像上传异常!", Toast.LENGTH_SHORT).show();
                break;
            default:
                break;
        }
    }
}
